<%= header %>
<!--
Verify that creating uninteresting mutation observer events doesn't hold an xhr beacon from being sent
-->
<script src="39-uninteresting-mo-followed-by-interesting.js" type="text/javascript"></script>
<%= boomerangScript %>
<script>

function createXHREvent() {
	// start a XHR
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "/assets/blank.html?rnd" + Math.random());
	xhr.addEventListener("load", function() {
		// create a non-interesting MO event right afterwards.
		// this should extend the timeout to 1s.
		var div = window.document.createElement("div");
		window.document.body.appendChild(div);

		// create an interesting MO event at 500ms.
		// this should trigger the beacon.
		setTimeout(function() {
			var img = window.document.createElement("img");
			img.src = "/delay?delay=1000&file=/assets/img.jpg?rnd" + Math.random();
			window.document.body.appendChild(img);
		}, 500);
	});
	xhr.send();
}

BOOMR_test.init({
	"instrument_xhr": true,
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 3 : 1,
	afterFirstBeacon:
		function() {
			if (!BOOMR.plugins.AutoXHR) {
				return;
			}
			// we want createXHREvent to run twice
			BOOMR.subscribe("beacon", createXHREvent, null, null, true);
			createXHREvent();
		}
});
</script>
<%= footer %>
